package com.slwish.xty.ui.activity;

import android.content.Intent;
import android.support.v7.widget.OrientationHelper;
import android.view.View;

import com.applikeysolutions.cosmocalendar.view.CalendarView;
import com.slwish.common.base.ToolbarActivity;
import com.slwish.common.utils.TimeUtils;
import com.slwish.xty.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class ChoseTimeActivity extends ToolbarActivity {
    @BindView(R.id.calendar_view)
    public CalendarView calendarView;
    List<String> longList = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.act_chose_time;
    }

    @Override
    protected void initWidget() {
        super.initWidget();
        setTitle(R.string.chose_time_title);
        calendarView.setCalendarOrientation(OrientationHelper.HORIZONTAL);
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        calendarView.setOnSelectRangeTimeListener(new CalendarView.OnSelectRangeTimeListener() {
            @Override
            public void onSelect(List<String> times) {
                longList = times;
//                LogUtils.i("xx","time-->"+times.toString());
            }
        });
    }

    @OnClick(R.id.tv_submit)
    public void setOnClick(View view) {
        String nowDateString = TimeUtils.getCurTimeString(TimeUtils.NO_HOUR_SDF);
        long nowDate = TimeUtils.string2Milliseconds(nowDateString, TimeUtils.NO_HOUR_SDF);
        if (longList == null || longList.size() < 1) {
            showToast(R.string.toast_chose_start_time_text);
        } else {
            if ((Long.valueOf(longList.get(0)) - nowDate) >= 0) {
                Intent intent = new Intent();
                intent.putStringArrayListExtra("list", (ArrayList<String>) longList);
                setResult(100, intent);
                finish();
            } else {
                showToast(R.string.toast_chose_time_failed_text);
            }


        }
    }
}
